package org.framework.edge.builder.infrastructure.persistence;

import jakarta.annotation.Resource;
import org.framework.edge.builder.domain.model.docker.builder.module.DockerBuildModule;
import org.framework.edge.builder.domain.model.docker.builder.module.DockerBuildModuleRepository;
import org.framework.edge.builder.infrastructure.converter.DockerBuildModuleConverter;
import org.framework.edge.builder.infrastructure.entity.DockerBuildModuleDO;
import org.springframework.stereotype.Repository;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;

import java.util.List;
import java.util.stream.Collectors;
/**
 * describe 打包模块 
 *
 * @author Jia wei Wu
 * @date 2024/08/13 07:39 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence 
 **/
@Repository
public class DockerBuildModuleRepositoryImpl  implements  DockerBuildModuleRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增打包模块
     *
     * @param dockerBuildModule 新增打包模块     
     * @return {@link Result<DockerBuildModule>} 打包模块新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModule> story(DockerBuildModule dockerBuildModule) {
        DockerBuildModuleDO dockerBuildModuleDO = DockerBuildModuleConverter.INSTANCE.fromDockerBuildModule(dockerBuildModule);
        lazyLambdaStream.upsert(dockerBuildModuleDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增打包模块
     *
     * @param dockerBuildModuleList 批量新增打包模块     
     * @return {@link Result<List<DockerBuildModule>>} 打包模块新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<List<DockerBuildModule>> batchStory(List<DockerBuildModule> dockerBuildModuleList) {
        List<DockerBuildModuleDO> dockerBuildModuleDOList = dockerBuildModuleList.stream().map(DockerBuildModuleConverter.INSTANCE::fromDockerBuildModule).collect(Collectors.toList());
        lazyLambdaStream.upsert(dockerBuildModuleDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个打包模块
     *
     * @param dockerBuildModule 查询单个打包模块     
     * @return {@link Result<DockerBuildModule>} 打包模块领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModule> findOne(DockerBuildModule dockerBuildModule) {
        DockerBuildModuleDO dockerBuildModuleDO = DockerBuildModuleConverter.INSTANCE.fromDockerBuildModule(dockerBuildModule);
        DockerBuildModule dockerBuildModuleOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(dockerBuildModuleDO), DockerBuildModule.class);
        return ResultFactory.successOf(dockerBuildModuleOne);
    }

    /**
     * describe 查询多个打包模块
     *
     * @param dockerBuildModule 查询多个打包模块     
     * @return {@link Result<List<DockerBuildModule>>} 打包模块领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<List<DockerBuildModule>> findList(DockerBuildModule dockerBuildModule) {
        DockerBuildModuleDO dockerBuildModuleDO = DockerBuildModuleConverter.INSTANCE.fromDockerBuildModule(dockerBuildModule);
        List<DockerBuildModule> dockerBuildModuleList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(dockerBuildModuleDO), DockerBuildModule.class);
        return ResultFactory.successOf(dockerBuildModuleList);
    }

    /**
     * describe 分页查询多个打包模块
     *
     * @param size 当前页数
     * @param current 当前页
     * @param dockerBuildModule 分页查询多个打包模块     
     * @return {@link Result<LazyPage<DockerBuildModule>>} 分页打包模块领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<LazyPage<DockerBuildModule>> findPage(int size,int current,DockerBuildModule dockerBuildModule) {
        DockerBuildModuleDO dockerBuildModuleDO = DockerBuildModuleConverter.INSTANCE.fromDockerBuildModule(dockerBuildModule);
        LazyPage<DockerBuildModule> lazyPage = new LazyPage<>(current,size);
        LazyPage<DockerBuildModule> dockerBuildModuleLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(dockerBuildModuleDO),lazyPage, DockerBuildModule.class);
        return ResultFactory.successOf(dockerBuildModuleLazyPage);
    }

    /**
     * describe 删除打包模块
     *
     * @param dockerBuildModule 删除打包模块     
     * @return {@link Result<DockerBuildModule>} 打包模块     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModule> remove(DockerBuildModule dockerBuildModule) {
        DockerBuildModuleDO dockerBuildModuleDO = DockerBuildModuleConverter.INSTANCE.fromDockerBuildModule(dockerBuildModule);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(dockerBuildModuleDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在打包模块
     *
     * @param dockerBuildModule 打包模块领域对象     
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<Boolean> exists(DockerBuildModule dockerBuildModule) {
        DockerBuildModuleDO dockerBuildModuleDO = DockerBuildModuleConverter.INSTANCE.fromDockerBuildModule(dockerBuildModule);
        Boolean exists=lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(dockerBuildModuleDO));
        return ResultFactory.successOf(exists);
    }

}